package com.tools.web.interceptor.auth._common;

import com.tools.common.container.OwnPairs;
import com.tools.common.object.Note;
import com.tools.web.interceptor.auth.GenericAuthUser;
import com.tools.web.interceptor.auth.LoginDeviceType;

import java.util.LinkedHashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 用户的登录记录的用户认证包装类
 * 该类的实现可以允许用户多个在线记录
 * */
@Note("用户的登录记录的用户认证包装类" +
        "该类的实现可以允许用户多个在线记录")
public final class MultipleAuthUser extends GenericAuthUser {

    @Note("【2选1】：每个设备对应的登录记录以及它们的过期时间（毫秒）")
    private ConcurrentHashMap<String, LinkedHashMap<String, Long>> keyAndDeviceAndLoginRecordMap;

    /* **************************************************************************************
     *
     *          构造器
     *
     * **************************************************************************************
     * */
    
    public MultipleAuthUser(Object userId, String loginDeviceType, Object user,
                         Map roleKeyMap, Map permissionIds,
                         Iterable<?> routers) {
        super(userId, loginDeviceType, user, roleKeyMap, permissionIds, routers);
    }
    
    public static MultipleAuthUser of(Object userId, String loginDeviceType, Object user,
                                      Map roleKeyMap, Map permissionIds,
                                      Iterable<?> routers) {
        return new MultipleAuthUser(userId, loginDeviceType, user, roleKeyMap, permissionIds, routers);
    }

    /* **************************************************************************************
     *
     *          自定义方法
     *
     * **************************************************************************************
     * */

    ConcurrentHashMap<String, LinkedHashMap<String, Long>> getKeyAndDeviceAndLoginRecordMap() {
        return keyAndDeviceAndLoginRecordMap;
    }

    ConcurrentHashMap<String, LinkedHashMap<String, Long>> keyAndDeviceAndLoginRecordMapOrDefault() {
        if(this.keyAndDeviceAndLoginRecordMap == null) {
            this.keyAndDeviceAndLoginRecordMap = new ConcurrentHashMap<>();
        }
        return this.keyAndDeviceAndLoginRecordMap;
    }

    /* **************************************************************************************
     *
     *          重写的方法
     *
     * **************************************************************************************
     * */
    
    @Override
    protected String protected_toStringPropertyString() {
        return "keyAndDeviceAndLoginRecordMap=" + keyAndDeviceAndLoginRecordMap + ", ";
    }

    @Override
    public MultipleAuthUser uuid(String uuid) {
        super.uuid(uuid);
        return this;
    }

    @Override
    public MultipleAuthUser userId(Object userId) {
        super.userId(userId);
        return this;
    }

    @Override
    public MultipleAuthUser userId(String userId) {
        super.userId(userId);
        return this;
    }

    @Override
    public MultipleAuthUser userId(long userId) {
        super.userId(userId);
        return this;
    }

    @Override
    public MultipleAuthUser userId(int userId) {
        super.userId(userId);
        return this;
    }

    @Override
    public MultipleAuthUser loginDeviceType(String loginDeviceType) {
        super.loginDeviceType(loginDeviceType);
        return this;
    }

    @Override
    public MultipleAuthUser loginDeviceType(LoginDeviceType loginDeviceType) {
        super.loginDeviceType(loginDeviceType);
        return this;
    }

    @Override
    public MultipleAuthUser loginUserType(String loginUserType) {
        super.loginUserType(loginUserType);
        return this;
    }

    @Override
    public MultipleAuthUser user(Object user) {
        super.user(user);
        return this;
    }

    @Override
    public MultipleAuthUser userTypeClass(String userTypeClassName) {
        super.userTypeClass(userTypeClassName);
        return this;
    }

    @Override
    public MultipleAuthUser userTypeClass(Class<?> userTypeClass) {
        super.userTypeClass(userTypeClass);
        return this;
    }

    @Override
    public MultipleAuthUser roleKeyMap(Map roleKeyMap) {
        super.roleKeyMap(roleKeyMap);
        return this;
    }

    @Override
    public MultipleAuthUser roleKeyMap(OwnPairs roleKeyPairs) {
        super.roleKeyMap(roleKeyPairs);
        return this;
    }

    @Override
    public MultipleAuthUser permKeyMap(Map permKeyMap) {
        super.permKeyMap(permKeyMap);
        return this;
    }

    @Override
    public MultipleAuthUser permKeyMap(OwnPairs permKeyPairs) {
        super.permKeyMap(permKeyPairs);
        return this;
    }

    @Override
    public MultipleAuthUser routerList(Iterable routerList) {
        super.routerList(routerList);
        return this;
    }

    @Override
    public MultipleAuthUser customData(Map<String, Object> customData) {
        super.customData(customData);
        return this;
    }

    @Override
    public MultipleAuthUser customData(OwnPairs<String, Object> customData) {
        super.customData(customData);
        return this;
    }

    @Override
    public MultipleAuthUser customData(Object javaBean) {
        super.customData(javaBean);
        return this;
    }

    @Override
    public MultipleAuthUser customData(String jsonObject) {
        super.customData(jsonObject);
        return this;
    }

    @Override
    public MultipleAuthUser putData(String name, Object value) {
        super.putData(name, value);
        return this;
    }

    @Override
    public MultipleAuthUser putAllData(Map customData) {
        super.putAllData(customData);
        return this;
    }

    @Override
    public MultipleAuthUser putAllData(OwnPairs customData) {
        super.putAllData(customData);
        return this;
    }

    @Override
    public MultipleAuthUser putAllData(String jsonObject) {
        super.putAllData(jsonObject);
        return this;
    }

    @Override
    public MultipleAuthUser putAllData(Object javaBean) {
        super.putAllData(javaBean);
        return this;
    }

    @Override
    public MultipleAuthUser removeData(String name) {
        super.removeData(name);
        return this;
    }

    @Override
    public MultipleAuthUser removeAllData(String... names) {
        super.removeAllData(names);
        return this;
    }

    @Override
    public MultipleAuthUser removeAllData(Iterable<String> names) {
        super.removeAllData(names);
        return this;
    }

    @Override
    public MultipleAuthUser clearData() {
        super.clearData();
        return this;
    }
    
    
}
